const vmData = {
    vmHouseList: {
        houseList: [],
        currentPage: 1,
    },
};

const vmHouseList = new Vue({
    el: '.house-list-container',
    data: vmData.vmHouseList,
    methods: {
        clickHouseEvent,
    },
});

function apiready() {
    fxj.fixLayout();
    reqCollectHouseList();
}

async function reqCollectHouseList() {
    const res = await ajax({
        url: 'home/userCenter/getUserCollect',
        data: {
            pageNum: vmHouseList.currentPage,
        },
    });
    if (res.data !== null) {
        forEach(res.data.list.houseData, house => {
            house.img = fxj.fixImgUrl(house.img);
        });
        vmHouseList.houseList = res.data.list.houseData;
    }
}

function clickHouseEvent(evt, house) {
    const target = evt.target;
    if ([...target.classList].includes('icon-xin')) {
        target.querySelector('.icon').classList.toggle('collected');
        fxj.api.collectHouse(house.id).then(
            res => {
                toast(res.msg);
            },
        );
    }
    else {
        const close = fxj.dialog.loading({noBg: true});
        goPage(`house_res_detail.html?id=${house.id}`);
        setTimeout(() => {
            close();
        }, 2000);
    }
}